<template>
	<Maximize v-if="themeConfig.maximize" />
	<Tabs v-if="themeConfig.tabs" />
	<!-- <el-scrollbar> -->
	<el-main>
		<router-view v-slot="{ Component, route }">
			<!-- transition暂时缓存页面报表会有点问题，需求重新刷新页面 -->
			<transition appear name="fade-transform" mode="out-in">
				<keep-alive :include="authStore.keepAliveRouter">
					<suspense>
						<template #default>
							<component :is="Component" :key="route.path" v-if="route.path" />
						</template>
						<template #fallback>
							<Loading />
						</template>
					</suspense>
				</keep-alive>
			</transition>
		</router-view>
	</el-main>
	<!-- </el-scrollbar> -->
</template>

<script setup lang="ts">
import { ref, computed, nextTick, provide, onBeforeUnmount } from 'vue';
import { GlobalStore } from '@/stores';
import { AuthStore } from '@/stores/modules/auth';
import Maximize from './components/Maximize.vue';
import Tabs from '@/layouts/components/Tabs/index.vue';
// import Footer from "@/layouts/components/Footer/index.vue";
import Loading from '@/components/Loading/index.vue';
const authStore = AuthStore();
const globalStore = GlobalStore();
const themeConfig = computed(() => globalStore.themeConfig);
const isCollapse = computed(() => globalStore.themeConfig.isCollapse);
// console.log(authStore.keepAliveRouterGet);
// 刷新当前页面
const isRouterRefresh = ref(true);
const refreshCurrentPage = () => {
	isRouterRefresh.value = false;
	nextTick(() => {
		isRouterRefresh.value = true;
	});
};
provide('refresh', refreshCurrentPage);

// 监听窗口大小变化，折叠侧边栏
const screenWidth = ref<number>(0);
const listeningWindow = () => {
	screenWidth.value = document.body.clientWidth;
	if (!isCollapse.value && screenWidth.value < 1200) globalStore.setThemeConfig({ ...themeConfig.value, isCollapse: true });
	if (isCollapse.value && screenWidth.value > 1200) globalStore.setThemeConfig({ ...themeConfig.value, isCollapse: false });
};

window.addEventListener('resize', listeningWindow);
onBeforeUnmount(() => {
	window.removeEventListener('resize', listeningWindow);
});
</script>

<style scoped lang="scss">
.el-main {
	box-sizing: border-box;
	padding: 10px 12px;
	overflow-x: hidden;
	background-color: #f0f2f5;
	&::-webkit-scrollbar {
		background-color: #f0f2f5;
	}
}
.el-footer {
	height: auto;
	padding: 0;
}
</style>
